class myPromise {
    static PENDING = 'pending'
    static FULFILLED = 'fulfilled'
    static REJECTED = 'rejected'
    constructor(executor) {
        this.status = myPromise.PENDING
        this.value = null
        //使用try  是因为 外面使用不调用resolve  reject以外其他的 将会报错
        try {
            executor(this.resolve.bind(this), this.reject.bind(this))
        } catch (error) {
            this.reject(error)
        }
    }
    resolve(value) {
        if (this.status === myPromise.PENDING) {
            this.status = myPromise.FULFILLED
            this.value = value
        }

    }
    reject(reason) {
        if (this.status === myPromise.PENDING) {
            this.status = myPromise.REJECTED
            this.value = reason
        }

    }
}